/*
 * Item.java
 */

package nxtgeninventorysystem.Data;

import java.util.ArrayList;

/**
 * The Item class is meant to hold data from the Item entity so that it can
 * be easily passed as a parameter.
 * @author Seraph Softworks
 */
public class Item extends Data {

    private int id;
    private String name;
    private String type;
    private String description;
    private Person person;
    private boolean deleted;

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        if(name == null) {
            this.name = "";
            return;
        }
        this.name = name.replace("\\'","\'").replace("\\\"","\"");
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        if(type == null) {
            this.type = "";
            return;
        }
        this.type = type.replace("\\'","\'").replace("\\\"","\"");
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        if(description == null) {
            this.description = "";
            return;
        }
        this.description = description.replace("\\'","\'").replace("\\\"","\"");
    }

    /**
     * @return the deleted
     */
    public boolean isDeleted() {
        return deleted;
    }

    /**
     * @param deleted the deleted to set
     */
    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    /**
     * @return the person
     */
    public Person getPerson() {
        return person;
    }

    /**
     * @param person the person to set
     */
    public void setPerson(Person person) {
        this.person = person;
    }

    @Override
    public void reset() {

    }

    public ArrayList <String> getItemSearchParametersQueryStrings(ItemSearchOptions options) {
        ArrayList <String> conditions = new ArrayList <String> ();
        if (options.considerDescription()) {
            conditions.add("item.description like '%" + getDescription().replace("\'","\\'").replace("\"", "\\\"") + "%'");
        }
        if (options.considerId()) {
            conditions.add("item.id = " + getId());
        }
        if (options.considerAvailable()) {
            if(getPerson() == null)
                conditions.add("item.person is null");
            else
                conditions.add("item.person is not null");
        }
        if (options.considerName()) {
            conditions.add("item.name like '%" + getName().replace("\'","\\'").replace("\"", "\\\"") + "%'");
        }
        if (options.considerType()) {
            conditions.add("item.type = '" + getType().replace("\'","\\'").replace("\"", "\\\"") + "'");
        }
        return conditions;
    }

}
